package pt.isec.gpsgroup5.moneybox;

import java.util.Calendar;

public class Objective {
	
	private int id = -1;
	private String name = null;
	private float finalAmount = -1;
	private float currentAmount = -1;
	private int priority = -1;
	private int status = -1; 
	private int year = -1;
	private int month = -1;
	private int day = -1;
	
	private final int maxNameLength = 50;
	private final int minPriority = 1;
	private final int maxPriority = 3;
	private final int maxYear = 2099;
	private final float maxAmount = 1000000;
	private final int minStatus = 0;
	private final int maxStatus = 1;
	
	
	
	//Constructor
	public Objective(int id, String name, float finalAmount, float currentAmount, int year, int month, int day, int priority, int status) {
		setId(id);
		setName(name);
		setFinalAmount(finalAmount);
		setCurrentAmount(currentAmount);
		setPriority(priority);
		setYear(year);
		setMonth(month);
		setDay(day);
		setStatus(status);
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name the name to set
	 */
	public void setName(String name) {
		//If name's length is greater or equal than "maxNameLength"
		//the excess gets ignored
		if(name.length() >= maxNameLength) {
			name.substring(0, maxNameLength);
		}
		this.name = name;
	}

	/**
	 * @return the priority
	 */
	public int getPriority() {
		return priority;
	}

	/**
	 * @param priority the priority to set
	 */
	public void setPriority(int priority) {
		if (priority >= minPriority && priority <= maxPriority ) {
			this.priority = priority;
		}
	}

	/**
	 * @return the status
	 */
	public int getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(int status) {
		if(status >= minStatus && status <= maxStatus) {
			this.status = status;
		}
	}
	

	/**
	 * @return the finalAmount
	 */
	public float getFinalAmount() {
		return finalAmount;
	}

	/**
	 * @return the year
	 */
	public int getYear() {
		return year;
	}

	/**
	 * @param year the year to set
	 */
	public void setYear(int year) {
		int currentYear = Calendar.getInstance().get(Calendar.YEAR);
		if (year >= currentYear && year <= maxYear) {
			this.year = year;
		}
	}

	/**
	 * @return the month
	 */
	public int getMonth() {
		return month;
	}

	/**
	 * @param month the month to set
	 */
	public void setMonth(int month) {
		if (month >= 1 && month <= 12) {
			this.month = month;
		}
	}

	/**
	 * @return the day
	 */
	public int getDay() {
		return day;
	}

	/**
	 * @param day the day to set
	 */
	public void setDay(int day) {
		Calendar calendar = Calendar.getInstance();
		int maxDay = -1;
		
		if (year != -1 && month != -1) {
			calendar.set(year, month, 1);
			maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
			
			if(day >= 1 && day <= maxDay) {
				this.day = day;
			}	
		}
	}

	/**
	 * @param finalAmount the finalAmount to set
	 */
	public void setFinalAmount(float finalAmount) {
		if (finalAmount > 0 && finalAmount < maxAmount) {
			this.finalAmount = finalAmount;
		}
	}

	/**
	 * @return the currentAmount
	 */
	public float getCurrentAmount() {
		return currentAmount;
	}

	/**
	 * @param currentAmount the currentAmount to set
	 */
	public void setCurrentAmount(float currentAmount) {
		if (currentAmount > 0 && currentAmount < maxAmount) {
			this.currentAmount = currentAmount;
		}
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		if(id > 0) {
			this.id = id;
		}
	}


	
	
}
